package com.xxx.video.main.beans;

import android.media.MediaMetadataRetriever;
import android.text.TextUtils;
import java.io.File;

/**
 */
public class LocalMediaInfoBean {
    /**
     */
    public String path;
    /**
     */
    public String editPath;
    /**
     */
    public long duration;
    /**
     */
    public int width;
    /**
     */
    public int height;
    /**
     */
    public MediaType mMediaType;
    /**
     */
    public String pictureType;
    /**
     */
    public long fileSize;
    /**
     */
    public boolean isCheck;
    /**
     */
    public int drawable;
    /**
     *
     */
    public String compressPath;
    public long compressSize;
    /**
     */
    public boolean isUploadOver;
    /**
     *
     */
    public String faceUrl;
    /**
     */
    public boolean isNewTake;

    /**
     */
    public boolean isGif() {
        return !TextUtils.isEmpty(path) && path.toLowerCase().endsWith("gif");
    }


    /**
     */
    public String getLongText() {
        String text = "";
        if (duration == 0) {
            return "";
        }
        long mDuration = duration / 1000;
        if (mDuration < 60) {
            if (mDuration < 10) {
                text = "0:0" + mDuration;
            } else {
                text = "0:" + mDuration;
            }
        } else {
            text = ((int) mDuration / 60) + ":" + mDuration % 60;
        }
        return text;
    }

    public void initMediaSize() {
        MediaMetadataRetriever mmr = new MediaMetadataRetriever();
        try {
            mmr.setDataSource(new File(path).getAbsolutePath());
            String durations = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION);
            String widths = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
            String heights = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
            String rotate = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
            if (!TextUtils.isEmpty(durations)) {
                duration = Long.parseLong(durations);
            }
            if (!TextUtils.isEmpty(widths)) {
                width = Integer.parseInt(widths);
            }
            if (!TextUtils.isEmpty(heights)) {
                height = Integer.parseInt(heights);
            }
            if (!TextUtils.isEmpty(rotate)) {
                int parseInt = Integer.parseInt(rotate);
                if (parseInt / 90 % 2 != 0) {
                    int tempWidth = height;
                    height = width;
                    width = tempWidth;
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            mmr.release();
        }
    }


    public String getPicName() {
        if (!TextUtils.isEmpty(path)) {
            return path.substring(path.lastIndexOf("/"));
        } else {
            return "";
        }
    }
}
